/***************************************************************************
 * This document contains confidential and proprietary information
 * subject to non-disclosure agreements with AsiaInspection. This
 * information shall not be distributed or copied without written
 * permission from the AsiaInspection.
 ***************************************************************************/
package io;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.commons.io.FileUtils;

/***************************************************************************
 *<PRE>
 *  Project Name    : com.allen
 *
 *  Package Name    : io
 *
 *  File Name       : FileLineReader.java
 *
 *  Creation Date   : May 16, 2016
 *
 *  Author          : Allen Zhang
 *
 *  Purpose         : TODO
 *
 *
 *  History         : TODO
 *
 *</PRE>
 ***************************************************************************/

public class FileLineReader {
	public static void main(String args[]) throws IOException {
//		final String EXAMPLE_TEST =  "2016-05-15 10:21:30 AM 白云先生(80169078)";
//		System.out.println(EXAMPLE_TEST.matches("\\^2016"));


		File file = new File("D:\\chat.txt");
//		File file = new File("D:\\3.txt");
		List<String> lines = FileUtils.readLines(file, "UTF-8");
		boolean found = false;
		String keyword = "80169078";
		int stop = 0;
		String newLine = System.getProperty("line.separator");

		for (String line : lines) {
			if (line.startsWith("2016-10-17") && line.indexOf(keyword) > 0)	{
//			if (line.contains("白云先生") && line.indexOf(keyword) > 0)	{
//			if (line.startsWith("白云先生"))	{
				//found, next line is master's comment
				found = true;
				continue;
			}
			if (found) {
				//master's real comment
				System.out.println(line);
				found = false;
				if (stop > 2) {
					System.out.println(newLine);
					stop = 0;
				}
			} else {
				//other's comments
				stop++;
			}
		}
	}

}
